package com.sunfeng.chap2.p13;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2021/10/9  18:22
 */
public class Test13_22 {
    public static void main(String[] args) throws IOException, InterruptedException {
        RandomAccessFile randomAccessFile = new RandomAccessFile("D:\\nio\\a.txt", "rw");
        FileChannel channel = randomAccessFile.getChannel();


        FileLock lock = channel.lock(0, Long.MAX_VALUE, true);
        Thread.sleep(Integer.MAX_VALUE);
        lock.release();

    }
}
